package jjoms.model.main;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import jjoms.model.info.InfoVO;
import jjoms.model.item.ItemVO;
import jjoms.userException.UpdatedHitsInfoException;

import org.springframework.stereotype.Service;

@Service
public class MainServiceImpl implements MainService {
	@Resource(name = "mainDAOImpl")
	private MainDAO mainDAO;

	@Override
	public void NewsearchAllContents(String keyword) throws UpdatedHitsInfoException {
		ContentsVO cvo = null;
		// info 정보 가져오기
		InfoVO ivo = mainDAO.sectionFindByKeyword(keyword);
		if(ivo == null)
			ivo = mainDAO.divisionFindByKeyword(keyword);
		System.out.println("after search InfoVO = " + ivo);
		 
		// itemList 가져 오기
		List<ItemVO> list = mainDAO.NewgetItemList(keyword);
		System.out.println("after getItemList = "  + list);
		cvo = new ContentsVO(ivo , list);
		System.out.println("after searchAll method ContentsVO : " + cvo);
		
		if(cvo.getIvo() != null){
			throw new UpdatedHitsInfoException(cvo);			
		}
	//	return cvo;
	}

	/**
	 * 통합검색 - all
	 * 카티고리 검색 - info, item
	 */
	@Override
	public List<String> autoKeyword(String keyword, String kind) {
		List<String> keywordList = new ArrayList<String>();
		if(kind.equals("all")){
			keywordList = mainDAO.getAllListKeyword(keyword);
		}else{
			keywordList = mainDAO.categoryAutoKeyword(keyword, kind);
		}
		return keywordList;
	}
}
